package com.etime.shuhuiyuan.controllers.coursechapter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.ListMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.pojo.CourseChapter;
import com.etime.shuhuiyuan.services.coursechapter.interfaces.CourseChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CourseChapter示例的controller控制层
 */
@Api(tags = "courseChapter案例接口")
@RestController
@RequestMapping("/courseChapter")
public class CourseChapterController {

    @Autowired
    private CourseChapterService courseChapterService;

    @ApiOperation("添加courseChapter案例")
    @ApiImplicitParams({
//            @ApiImplicitParam(name="chapterid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chaptersummary",value="传递字符串"),
            @ApiImplicitParam(name="chapterpid",value="传递数字"),
            @ApiImplicitParam(name="chapterprice",value="传递两位小数"),
            @ApiImplicitParam(name="chapteroriginprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinmaxpoint",value="传递两位小数"),
            @ApiImplicitParam(name="chapterbuynum",value="传递数字"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name="chapteruserid",value="传递数字"),
            @ApiImplicitParam(name="chapterusertruename",value="传递字符串")
//            @ApiImplicitParam(name="chaptercreatetime",value="传递时间"),
//            @ApiImplicitParam(name="chapterupdatetime",value="传递时间")

    })
    @PostMapping("/inserts")
    public BaseMessage insertCourseChapter(CourseChapter courseChapter){
        BaseMessage msg = new BaseMessage();
        int rtn = courseChapterService.insertCourseChapter(courseChapter);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存courseChapter成功");
        }else{
            msg.setMsg("保存courseChapter失败");
        }
        return msg;
    }

    @ApiOperation("修改courseChapter案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chapterid",value = "自增长主键，必须传递"),
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chaptersummary",value="传递字符串"),
            @ApiImplicitParam(name="chapterpid",value="传递数字"),
            @ApiImplicitParam(name="chapterprice",value="传递两位小数"),
            @ApiImplicitParam(name="chapteroriginprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinmaxpoint",value="传递两位小数"),
            @ApiImplicitParam(name="chapterbuynum",value="传递数字"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name="chapteruserid",value="传递数字"),
            @ApiImplicitParam(name="chapterusertruename",value="传递字符串")
//            @ApiImplicitParam(name="chaptercreatetime",value="传递时间"),
//            @ApiImplicitParam(name="chapterupdatetime",value="传递时间")
    })
    @PostMapping("/updates")
    public BaseMessage updateCourseType(CourseChapter courseChapter){
        BaseMessage msg = new BaseMessage();
        int rtn = courseChapterService.updateCourseChapter(courseChapter);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存courseChapter成功");
        }else{
            msg.setMsg("保存courseChapter失败");
        }
        return msg;
    }
    @ApiOperation("查询courseChapter列表案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常")
    })
    @GetMapping("/list")
    public ListMessage<CourseChapter> selectCourseTypeList(CourseChapter courseChapter){
        ListMessage<CourseChapter> listMessage = new ListMessage<>();
        List<CourseChapter> list = courseChapterService.selectCourseChapterList(courseChapter);
        if(list!=null) {
            listMessage.setDatalist(list);
            listMessage.setCode(1);
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }

    @ApiOperation("分页查询courseChapter案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<CourseChapter> selectRoleByPage(CourseChapter courseChapter, Long pagenum, Long pagesize){
        Page<CourseChapter> pagedata = courseChapterService.selectCourseChapterByPage(courseChapter,pagenum,pagesize);
        PageMessage<CourseChapter> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }



    @ApiOperation("根据chapterid查询一条courseType信息的案例")
    @ApiImplicitParam("chapterid")
    @GetMapping("/get/{chapterid}")
    public PojoMessage<CourseChapter> selectCourseTypeById(@PathVariable("chapterid") int chapterid){
        PojoMessage<CourseChapter> msg = new PojoMessage<>();
        CourseChapter courseType = courseChapterService.selectCourseChapterById(chapterid);
        if(courseType!=null){
            msg.setCode(1);
            msg.setData(courseType);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }

    @ApiOperation("分页查询章的案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/courseChapter")
    public PageMessage<CourseChapter> selectCourseChapter(CourseChapter courseChapter, Long pagenum, Long pagesize){
        Page<CourseChapter> pagedata = courseChapterService.selectCourseChapterListByPage(courseChapter,pagenum,pagesize);
        PageMessage<CourseChapter> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("分页查询节的案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/courseKnot")
    public PageMessage<CourseChapter> selectCourseKnot(CourseChapter courseChapter, Long pagenum, Long pagesize){
        Page<CourseChapter> pagedata = courseChapterService.selectCourseKnotListByPage(courseChapter,pagenum,pagesize);
        PageMessage<CourseChapter> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("分页查询节的案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/courseKnot2")
    public PageMessage<CourseChapter> selectCourseKnot2(CourseChapter courseChapter, Long pagenum, Long pagesize,Integer pid){
        Page<CourseChapter> pagedata = courseChapterService.selectCourseKnotListByPage2(courseChapter,pagenum,pagesize,pid);
        PageMessage<CourseChapter> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("添加courseKnot案例")
    @ApiImplicitParams({
//            @ApiImplicitParam(name="chapterid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chaptersummary",value="传递字符串"),
            @ApiImplicitParam(name="chapterpid",value="传递数字"),
            @ApiImplicitParam(name="chapterprice",value="传递两位小数"),
            @ApiImplicitParam(name="chapteroriginprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinmaxpoint",value="传递两位小数"),
            @ApiImplicitParam(name="chapterbuynum",value="传递数字"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name="chapteruserid",value="传递数字"),
            @ApiImplicitParam(name="chapterusertruename",value="传递字符串")
//            @ApiImplicitParam(name="chaptercreatetime",value="传递时间"),
//            @ApiImplicitParam(name="chapterupdatetime",value="传递时间")

    })
    @PostMapping("/insert")
    public BaseMessage insertCourseKnot(CourseChapter courseChapter){
        BaseMessage msg = new BaseMessage();
        int rtn = courseChapterService.insertCourseChapter(courseChapter);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存courseKnot成功");
        }else{
            msg.setMsg("保存courseKnot失败");
        }
        return msg;
    }

    @ApiOperation("修改courseKnot案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="chapterid",value = "自增长主键，必须传递"),
            @ApiImplicitParam(name="chaptername",value="传递字符串"),
            @ApiImplicitParam(name="chaptersummary",value="传递字符串"),
            @ApiImplicitParam(name="chapterpid",value="传递数字"),
            @ApiImplicitParam(name="chapterprice",value="传递两位小数"),
            @ApiImplicitParam(name="chapteroriginprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinprice",value="传递两位小数"),
            @ApiImplicitParam(name="chaptercoinmaxpoint",value="传递两位小数"),
            @ApiImplicitParam(name="chapterbuynum",value="传递数字"),
            @ApiImplicitParam(name="chapterstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name="chapteruserid",value="传递数字"),
            @ApiImplicitParam(name="chapterusertruename",value="传递字符串")
//            @ApiImplicitParam(name="chaptercreatetime",value="传递时间"),
//            @ApiImplicitParam(name="chapterupdatetime",value="传递时间")
    })
    @PostMapping("/update")
    public BaseMessage updateCourseKnot(CourseChapter courseChapter){
        BaseMessage msg = new BaseMessage();
        int rtn = courseChapterService.updateCourseChapter(courseChapter);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存courseChapter成功");
        }else{
            msg.setMsg("保存courseChapter失败");
        }
        return msg;
    }

    @ApiOperation("根据chapterid查询一条courseType信息的案例")
    @ApiImplicitParam("chapterid")
    @GetMapping("/gets/{chapterid}")
    public PojoMessage<CourseChapter> selectCourseKnotById(@PathVariable("chapterid") int chapterid){
        PojoMessage<CourseChapter> msg = new PojoMessage<>();
        CourseChapter courseType = courseChapterService.selectCourseKnotById(chapterid);
        if(courseType!=null){
            msg.setCode(1);
            msg.setData(courseType);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }

    @ApiOperation("根据courseid查询章")
    @ApiImplicitParam("courseid")
    @GetMapping("/getChapterByCourseId")
    public ListMessage<CourseChapter> selectChapterByCourseId(CourseChapter courseChapter,Integer courseid){
        ListMessage<CourseChapter> listMessage = new ListMessage<>();
        List<CourseChapter> list = courseChapterService.selectChapterByCourseId(courseChapter,courseid);
        if(list!=null){
            listMessage.setCode(1);
            listMessage.setDatalist(list);
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有找到指定数据");
        }
        return listMessage;
    }


}

